/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  cn.hutool.core.util.StrUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.ComboBox
 *  javafx.scene.control.TextField
 *  javafx.scene.layout.AnchorPane
 *  javafx.util.StringConverter
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.deviceCheck;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.DeviceCheckUtil;
import com.gys.common.business.DeviceInfoUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.CacheUtil;
import com.gys.controller.BaseController;
import com.gys.controller.deviceCheck.DeviceCheckController;
import com.gys.data.deviceCheck.DeviceCheckInData;
import com.gys.data.deviceInfo.DeviceInfoInData;
import com.gys.data.deviceInfo.DeviceInfoOutData;
import com.gys.data.example.GetUserOutData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.util.StringConverter;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddDeviceCheckController
extends BaseController
implements Initializable {
    @FXML
    private AnchorPane anchorPane;
    @FXML
    private TextField gsdcBrId;
    @FXML
    private TextField gsdcBrName;
    @FXML
    private ComboBox<DeviceInfoOutData> gsdcDevice;
    @FXML
    private TextField gsdcDeviceModel;
    @FXML
    private TextField gsdcCheckRemarks;
    @FXML
    private TextField gsdcCheckResult;
    @FXML
    private TextField gsdcCheckStep;
    @Autowired
    private DeviceCheckController deviceCheckController;

    public void initialize(URL location, ResourceBundle resources) {
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isNull(this.anchorPane)) {
            return;
        }
        this.gsdcDevice.setValue(null);
        this.gsdcDeviceModel.clear();
        this.gsdcCheckRemarks.clear();
        this.gsdcCheckResult.clear();
        this.gsdcCheckStep.clear();
        GetUserOutData user = (GetUserOutData)CacheUtil.get("logInUser");
        this.gsdcBrId.setText(user.getDepId());
        this.gsdcBrName.setText(user.getDepName());
        DeviceInfoInData inData = new DeviceInfoInData();
        HttpJson rsp = DeviceInfoUtil.selectBrDeviceList(inData);
        if (rsp.isSuccess()) {
            List deviceList = JSON.parseArray((String)rsp.getMsg(), DeviceInfoOutData.class);
            this.gsdcDevice.setItems(FXCollections.observableArrayList((Collection)deviceList));
            this.gsdcDevice.converterProperty().set(new StringConverter<DeviceInfoOutData>(){

                public String toString(DeviceInfoOutData object) {
                    return object.getGsdiName();
                }

                public DeviceInfoOutData fromString(String string) {
                    return null;
                }
            });
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", rsp.getMsg());
            alert.showAndWait();
        }
    }

    @FXML
    private void deviceChange() {
        DeviceInfoOutData device = (DeviceInfoOutData)this.gsdcDevice.getValue();
        if (ObjectUtil.isNotNull(device)) {
            this.gsdcDeviceModel.setText(device.getGsdiModel());
        }
    }

    @FXML
    private void save() {
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        DeviceInfoOutData device = (DeviceInfoOutData)this.gsdcDevice.getValue();
        if (ObjectUtil.isNull(device)) {
            alert.setContentText("\u8bf7\u9009\u62e9\u8bbe\u5907");
            alert.showAndWait();
            return;
        }
        if (StrUtil.isNotBlank((CharSequence)this.gsdcCheckRemarks.getText()) && this.gsdcCheckRemarks.getText().length() > 30) {
            alert.setContentText("\u7ef4\u62a4\u5185\u5bb9\u957f\u5ea6\u4e0d\u8d85\u8fc730");
            alert.showAndWait();
            return;
        }
        if (StrUtil.isNotBlank((CharSequence)this.gsdcCheckResult.getText()) && this.gsdcCheckResult.getText().length() > 30) {
            alert.setContentText("\u68c0\u67e5\u60c5\u51b5\u957f\u5ea6\u4e0d\u8d85\u8fc730");
            alert.showAndWait();
            return;
        }
        if (StrUtil.isNotBlank((CharSequence)this.gsdcCheckStep.getText()) && this.gsdcCheckStep.getText().length() > 30) {
            alert.setContentText("\u8c03\u63a7\u63aa\u65bd\u957f\u5ea6\u4e0d\u8d85\u8fc730");
            alert.showAndWait();
            return;
        }
        DeviceCheckInData inData = new DeviceCheckInData();
        inData.setGsdcDeviceId(device.getGsdiId());
        inData.setGsdcDeviceName(device.getGsdiName());
        inData.setGsdcDeviceModel(device.getGsdiModel());
        inData.setGsdcCheckRemarks(this.gsdcCheckRemarks.getText().trim());
        inData.setGsdcCheckResult(this.gsdcCheckResult.getText().trim());
        inData.setGsdcCheckStep(this.gsdcCheckStep.getText().trim());
        HttpJson rsp = DeviceCheckUtil.save(inData);
        if (rsp.isSuccess()) {
            alert.setContentText("\u4fdd\u5b58\u6210\u529f");
            alert.showAndWait();
            this.closeWindow();
            this.init();
            this.deviceCheckController.initTable(0);
            this.deviceCheckController.getPagination().setCurrentPageIndex(0);
        } else {
            alert.setContentText(rsp.getMsg());
            alert.showAndWait();
        }
    }

    @FXML
    private void closeWindow() {
        this.anchorPane.getScene().getWindow().hide();
    }
}

